/**
 * 
 */
package com.swim.settlementrecord.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.swim.settlementrecord.entity.SettlementRecord;
import com.swim.settlementapply.entity.SettlementApply;
import com.swim.settlementapply.service.SettlementApplyService;
import com.swim.settlementrecord.dao.SettlementRecordDao;
import com.jeesite.modules.file.utils.FileUploadUtils;

/**
 * 结算记录Service
 * @author 刘军武
 * @version 2021-03-05
 */
@Service
@Transactional(readOnly=true)
public class SettlementRecordService extends CrudService<SettlementRecordDao, SettlementRecord> {
	
	@Autowired
	private SettlementApplyService settlementApplyService;
	
	/**
	 * 获取单条数据
	 * @param settlementRecord
	 * @return
	 */
	@Override
	public SettlementRecord get(SettlementRecord settlementRecord) {
		return super.get(settlementRecord);
	}
	
	/**
	 * 查询分页数据
	 * @param page 分页对象
	 * @param settlementRecord
	 * @return
	 */
	@Override
	public Page<SettlementRecord> findPage(Page<SettlementRecord> page, SettlementRecord settlementRecord) {
		return super.findPage(page, settlementRecord);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param settlementRecord
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(SettlementRecord settlementRecord) {
		super.save(settlementRecord);
		// 保存上传结算凭证文件
		FileUploadUtils.saveFileUpload(settlementRecord.getId(), "settlementRecord_file");
		//更改结算申请的申请状态为已结算
		SettlementApply settlementApply = new SettlementApply();
		settlementApply.setId(settlementRecord.getSettlementApplyId());		// 结算申请id
		settlementApply.setSettlementApplyState(2L);		// 申请状态 1表示结算中 2表示已结算
		settlementApplyService.update(settlementApply);
	}
	
	/**
	 * 更新状态
	 * @param settlementRecord
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(SettlementRecord settlementRecord) {
		super.updateStatus(settlementRecord);
	}
	
	/**
	 * 删除数据
	 * @param settlementRecord
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(SettlementRecord settlementRecord) {
		super.delete(settlementRecord);
	}
	
}